import serve from "@/utils/serve";

export interface ShopListData{
    id: number;
    userId: string;
    skuId: number;
    cartPrice: number;
    skuNum: number;
    imgUrl: string;
    skuName: string;
    isChecked: number;
    createTime: string;
    operateTime: string;
    isOrdered: number;
    orderTime: string;
    sourceType: string;
    sourceId: number;
    skuPrice: number;
    couponInfoList: null;
}
export type shopData={
    code:200
    data: shopcartListData[]
    message:string
    ok:boolean
}
export interface orderDetailData{
    id: null,
    orderId: null,
    skuId: number,
    skuName: string,
    imgUrl: string,
    orderPrice: number,
    skuNum: number,
    hasStock: null
}
export type tradeInfoData={
    tradeNo:string
    consignee:string
    consigneeTel:string
    deliveryAddress:string
    paymentWay:string
    orderComment:string
    orderDetailList:orderDetailData[]
}

export interface shopcartListData{
    activityRuleList:null
    cartInfoList: ShopListData[]
    createTime: string
}

export interface tokenData{
    token:string
    code: number
    data: {
        nickName: string, 
        name: string, 
        userId: number, 
        token: string
    }
    message: string
    ok: boolean

}
export interface gettokenData{
    phone:string,
    password:string
}

export default{
    getShopList(){
        return serve.get<any,shopData>('/api/cart/cartList')
    },
    // 改变选中状态
    reqCheckCart (skuId:number, isChecked:number) {
        return serve.get(`/api/cart/checkCart/${skuId}/${isChecked}`)
    },
    removeShop(skuId:number){
        return serve.delete<any,null>(`/api/cart/deleteCart/${skuId}`)
    },
    // 获取交易页面的商品信息
    reqTradeInfo(){
        return serve.get<any,ShopListData[]>('/api/order/auth/trade')
    },
    // 提交订单、获取支付信息
    reqSubmitOrder(tradeNo:string,data:tradeInfoData){
        return serve.post<any,number>(`/api/order/auth/submitOrder?tradeNo=${tradeNo}`, data)
    },
    
    reqPay (orderId:number) {
        return serve.get(`/api/payment/weixin/createNative/${orderId}`)
    },
    getToken(params:gettokenData){
        return serve.post<any,tokenData>('/api/user/passport/login',params)
    }
}